﻿namespace HiMap.MapControls.Tools
{
    using HiMap.Carto;
    using HiMap.Geometry;
    using HiMap.MapControls.Tools.Frm;
    using System;

    public class CommandGotoXY : CommandClass
    {
        protected internal override void OnClick()
        {
            Map map = base.Map.Map;
            FrmXY mxy = new FrmXY();
            mxy.ShowDialog();
            double x = mxy.X;
            double y = mxy.Y;
            if ((x != 0) || (y != 0))
            {
                double num3 = map.Envelope.MaxX - map.Envelope.MinX;
                double num4 = map.Envelope.MaxY - map.Envelope.MinY;
                IEnvelope envelope = new EnvelopeClass();
                envelope.MinX = x - ((num3 / ((double) base.Map.Size.Width)) * (base.Map.Size.Width / 2));
                envelope.MaxX = x + ((num3 / ((double) base.Map.Size.Width)) * (base.Map.Size.Width / 2));
                envelope.MinY = y + ((num4 / ((double) base.Map.Size.Height)) * (base.Map.Size.Height / 2));
                envelope.MaxY = y - ((num4 / ((double) base.Map.Size.Height)) * (base.Map.Size.Height / 2));
                map.Envelope = envelope;
                base.Map.MapRefresh();
            }
        }
    }
}

